﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using HXDNB.Infrastructure;
using HXDNB.Infrastructure.Helper;
using HXDNB.Test.Model;

namespace HXDNB.Test
{
    class Program
    {
        static void Main()
        {
            Console.WriteLine("Read Template...");
            Log.Info("HXDNB.Test.Program.Main", "读取模板文件...");

            var nv = new NVelocityHelper();

            Console.WriteLine("Set For...");
            nv.Put("List", GetData());
            nv.Deploy("NList.htm",@"/News/list.html");

            var sw = Stopwatch.StartNew();

            for (int i = 0; i < 100; i++)
            {
                //Console.WriteLine("Set Model...");
                nv.Put("Model", new TestModel { Id = i, Name = "&&&&SJX" + i, Remark = i + @"!@#$%^&*()<>?/';|\[]{}Good!!!!" });

                //Console.WriteLine("Save File...");
                nv.Deploy("NDetail.htm",@"/News/Test" + i + ".html");
            }
            sw.Stop();
            Console.WriteLine("nvelocity10000:" + sw.ElapsedMilliseconds);

            //using (var he = new HtmlEngine())
            //{
            //    //he.Load("List.htm");

            //    //Console.WriteLine("Set For...");
            //    //he.SetFor("divFor", GetData());
            //    //Log.Info("HXDNB.Test.Program.Main", "处理循环结构...");

            //    var sw1 = Stopwatch.StartNew();

            //    for (int i = 0; i < 100; i++)
            //    {
            //        he.Load("Detail.htm");

            //        //Console.WriteLine("Set Model...");
            //        he.SetModel(new TestModel { Id = i, Name = "SJX" + i, Remark = i + "Good!!!!" });

            //        //Console.WriteLine("Save File...");
            //        he.Deploy(@"/News/Test" + i + ".html");
            //        //Log.Info("HXDNB.Test.Program.Main", "创建文件Test" + i + ".html");
            //    }
            //    sw1.Stop();
            //    Console.WriteLine("htmlEngine100:" + sw1.ElapsedMilliseconds);

                //    //压缩打包待发布文件
                //    Zip.ZipDir(Config.Release);

                //    //Json.Save(Environment.CurrentDirectory + @"/Data/menu.json", GetMenus());
            //}

            Console.WriteLine("OK!!");
            Console.ReadKey();
        }

        static IEnumerable<TestModel> GetData()
        {
            var list = new List<TestModel>();
            for (int i = 0; i < 20; i++)
            {
                var model = new TestModel
                    {
                        Id = i,
                        Name = "Name_" + i,
                        Remark = "My &&&<>Name is Name_" + i
                    };
                list.Add(model);
            }
            return list;
        }

        static IEnumerable<Menu> GetMenus()
        {
            return new List<Menu>
                {
                    new Menu{Name="Index",Url="Index.html"},
                    new Menu{Name="List",Url="List.html"},
                    new Menu{Name="Detail",Url="Detail.html"},
                    new Menu{Name="Test",Url="Test.html"},
                    new Menu{Name="1hai",Url="http://www.1hai.cn"},
                    new Menu{Name="Baidu",Url="http://www.baidu.cn"}
                };
        }
    }
}
